package com.cx.java8;

import java.util.concurrent.TimeUnit;
import java.util.function.Supplier;

/**
 * @Author:chenxiaoyi
 * @Date:2020/9/14 16:47
 */
public class TimeUtils {

    public static void main(String[] args) {
        TimeUtils timeUtils = new TimeUtils();
    }

    public void test1(){
        try {
            TimeUnit.SECONDS.sleep(3);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }

    public void test2(){
        try {
            TimeUnit.SECONDS.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    public static  <T> T  executionTime(Supplier<T> sup) {

        long startTime = System.currentTimeMillis();
        T t = sup.get();
        System.out.println("执行时间:  "+(System.currentTimeMillis() - startTime)+"ms");
        return t;
    }

//    private <T> T static void computeTime(Supplier<T> supplier){
//        long start = System.currentTimeMillis();
//        consumer.accept(1);
//
//        System.out.println("执行时间:  "+(System.currentTimeMillis() - start));
//
//
//    }




}
